package mes.kanban.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.web.util.WebUtils;
import org.springframework.beans.BeanUtils;

import mes.kanban.config.KVRedisConfig;
import mes.kanban.entity.MesUser;

/**
 * 获得session里的用户信息
 * @author gjy
 *
 * 2018年3月2日上午11:20:18
 */
public class GetSessionUtil {
	
	/**
	 * 返回整个user
	 * @param request
	 * @return
	 */
	public static MesUser getUserInfo(HttpServletRequest request) {
		
		HttpSession session = WebUtils.toHttp(request).getSession();
		
		Object o = session.getAttribute(KVRedisConfig.SESSION_ATTRIBUTE_USER.getHaskey());
		
		MesUser user = new MesUser();
		
		BeanUtils.copyProperties(o, user);
		
		return user;
		
	}
	
	public static String getUserInfoToOther(HttpServletRequest request,String key) {
		
		HttpSession session = WebUtils.toHttp(request).getSession();
		
		Object o = session.getAttribute(key);
		
		return String.valueOf(o);
		
	}

}
